package tuanda.soict.firstsun.AbilityPackage;

import java.util.ArrayList;

import tuanda.soict.firstsun.DataPackage.ArmyDataSet;
import tuanda.soict.firstsun.DataPackage.AttributeList;
import tuanda.soict.firstsun.LogicPackage.Army;
import tuanda.soict.firstsun.LogicPackage.Coordinate;
import tuanda.soict.firstsun.LogicPackage.Scenario;

/**
 * @author tuanda_soict_hut
 * @version 0.0.1
 * @since 9-9-2012
 */
public class Promote_Ability extends Ability implements AttributeList {

	public Promote_Ability(int id, String name, int range, int area, int affect) {
		super(id, name, range, area, affect);
	}

	@Override
	public void mainAct(Army army, Scenario scenario) {
		String name = army.getName();
		int id = army.getID();
		int groupID = army.getGroupID();
		int x = army.getLocationX();
		int y = army.getLocationY();

		scenario.removeArmy(id, groupID, x, y);
		ArmyDataSet chosenArmyDataSet = null;
		Army transformedArmy = null;

		if (name.equalsIgnoreCase("WATER_ELEMENTAL")) {
			chosenArmyDataSet = ArmyDataSet.SOLDIER.getArmyData(44);
		} else if (name.equalsIgnoreCase("FIRE_ELEMENTAL")) {
			chosenArmyDataSet = ArmyDataSet.SOLDIER.getArmyData(45);
		} else if (name.equalsIgnoreCase("AIR_ELEMENTAL")) {
			chosenArmyDataSet = ArmyDataSet.SOLDIER.getArmyData(46);
		} else if (name.equalsIgnoreCase("EARTH_ELEMENTAL")) {
			chosenArmyDataSet = ArmyDataSet.SOLDIER.getArmyData(47);
		} else if (name.equalsIgnoreCase("LIGHT_ELEMENTAL")) {
			chosenArmyDataSet = ArmyDataSet.SOLDIER.getArmyData(48);
		} else if (name.equalsIgnoreCase("DARK_ELEMENTAL")) {
			chosenArmyDataSet = ArmyDataSet.SOLDIER.getArmyData(49);
		}

		transformedArmy = scenario.addInitialArmy(chosenArmyDataSet, groupID,
				x, y);

		if (transformedArmy != null) {
			transformedArmy.setLevel(4);
			transformedArmy.setActionLeft(false);
			transformedArmy.setMoveLeft(false);
			transformedArmy.setHealth((int) (0.8f * DEFAULT_UNIT_HEALTH));
			transformedArmy.setExperience(army.getExperience()
					+ (abilityLevel + 10) * army.getRank(), armyManager);
			transformedArmy.setLevel(1);
		}
	}

	@Override
	public void calculation(Army army, Scenario scenario) {
		this.setAbilityPoint((20 + getAbilityLevel()) * army.getRank());
	}

	@Override
	public ArrayList<Coordinate> calculateAffectedArea(Army army,
			Scenario scenario) {
		ArrayList<Coordinate> temp = new ArrayList<Coordinate>();
		temp.add(new Coordinate(army.getLocationX(), army.getLocationY()));
		return temp;
	}
}
